<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>传输列表 - Multi Transfer</title>
    <!-- Bootstrap CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="/font/bootstrap-icons.css" rel="stylesheet">
    <!-- 自定义样式 -->
    <style>
        body {
            background-color: #f8f9fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .navbar {
            background-color: #4a6cf7 !important;
            box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
        }

        .card {
            border: none;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 16px rgba(0, 0, 0, .12);
        }

        .transfer-item {
            padding: 15px;
            margin-bottom: 15px;
            border-left: 4px solid #4a6cf7;
        }

        .transfer-item:last-child {
            margin-bottom: 0;
        }

        .btn-primary {
            background-color: #4a6cf7;
            border-color: #4a6cf7;
        }

        .btn-primary:hover {
            background-color: #3a5ce5;
            border-color: #3a5ce5;
        }

        .download-link {
            color: #28a745;
            text-decoration: none;
            font-weight: 500;
        }

        .download-link:hover {
            color: #218838;
            text-decoration: underline;
        }

        .date-text {
            color: #6c757d;
            font-size: 0.9rem;
        }

        .empty-state {
            text-align: center;
            padding: 40px 20px;
            color: #6c757d;
        }

        .empty-state i {
            font-size: 4rem;
            color: #dee2e6;
            margin-bottom: 20px;
        }

        .transfer-title {
            font-weight: 600;
            color: #212529;
            margin-bottom: 5px;
        }

        .transfer-title:hover {
            color: #4a6cf7;
        }

        /* QR code modal styles */
        .qr-modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
        }

        .qr-modal-content {
            background-color: #fff;
            margin: 15% auto;
            padding: 20px;
            border-radius: 10px;
            width: 300px;
            text-align: center;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }

        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
        }

        .close:hover {
            color: black;
        }

        #qrcode {
            margin: 15px 0;
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark">
    <div class="container">
        <a class="navbar-brand" href="#">
            <i class="bi bi-cloud-arrow-up"></i> Multi Transfer
        </a>
        <button class="navbar-toggler" data-bs-target="#navbarNav" data-bs-toggle="collapse" type="button">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="#">传输列表</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/transfer/new}">新传输</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#" id="qrCodeBtn">
                        <i class="bi bi-qr-code"></i>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- 二维码模态框 -->
<div class="qr-modal" id="qrModal">
    <div class="qr-modal-content">
        <span class="close">&times;</span>
        <h5>扫描二维码访问此页面</h5>
        <div id="qrcode">
            <img alt="QR Code" id="qrCodeImage" src="" style="width: 200px; height: 200px;">
        </div>
        <p>使用手机扫描上方二维码可在移动设备上打开此页面</p>
    </div>
</div>

<!-- 主要内容 -->
<div class="container mt-4">
    <div class="row mb-4">
        <div class="col-md-8">
            <h1 class="display-5 fw-bold">传输列表</h1>
            <p class="lead">查看和管理所有传输项目</p>
        </div>
        <div class="col-md-4 text-end">
            <a class="btn btn-primary btn-lg mt-3" th:href="@{/transfer/new}">
                <i class="bi bi-plus-circle"></i> 新传输
            </a>
        </div>
    </div>

    <!-- 传输列表 -->
    <div class="card p-4 mb-5" th:if="${items}">
        <div class="transfer-item" th:each="it : ${items}">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <a class="transfer-title text-decoration-none"
                       th:href="@{/transfer/{id}(id=${it.id})}"
                       th:text="${it.content}">传输内容</a>
                    <div class="date-text">
                        <i class="bi bi-calendar3"></i>
                        <span th:text="${it.createdAt}">创建时间</span>
                        <span class="ms-3" th:if="${it.storedFilename}">
                                <i class="bi bi-paperclip"></i> 包含附件
                            </span>
                    </div>
                </div>
                <div class="col-md-4 text-end">
                    <div>
                        <a class="btn btn-danger btn-sm"
                           th:href="@{/transfer/{id}/delete(id=${it.id})}">
                            <i class="bi bi-trash"></i> 删除
                        </a>
                    </div>
                    <div th:if="${it.storedFilename}">
                        <a class="download-link"
                           th:href="@{/transfer/{id}/download(id=${it.id})}">
                            <i class="bi bi-download"></i> 下载附件
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 空状态 -->
    <div class="empty-state" th:unless="${items}">
        <i class="bi bi-inbox"></i>
        <h3>暂无传输项目</h3>
        <p>点击上方"新传输"按钮创建您的第一个传输项目</p>
    </div>
</div>

<!-- 页脚 -->
<footer class="bg-light text-center py-3 mt-5">
    <div class="container">
        <p class="mb-0 text-muted">© 2023 Multi Transfer. All rights reserved.</p>
    </div>
</footer>

<!-- Bootstrap JS -->
<script src="/js/bootstrap.bundle.min.js"></script>
<script>
    // 获取模态框元素
    const modal = document.getElementById("qrModal");
    const btn = document.getElementById("qrCodeBtn");
    const span = document.getElementsByClassName("close")[0];

    // 当用户点击二维码按钮时，打开模态框
    btn.onclick = function (event) {
        event.preventDefault();
        modal.style.display = "block";

        // 设置二维码图片的源为后端生成的二维码
        document.getElementById("qrCodeImage").src = "/transfer/qrcode?" + new Date().getTime();
    }

    // 当用户点击关闭按钮时，关闭模态框
    span.onclick = function () {
        modal.style.display = "none";
    }

    // 当用户点击模态框外部时，关闭模态框
    window.onclick = function (event) {
        if (event.target == modal) {
            modal.style.display = "none";
        }
    }
</script>
</body>
</html>